﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mes5GService.Migrations
{
    public partial class _20211015 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_FileWorkSteps_FileProcessess_FileProcessesId",
                table: "FileWorkSteps");

            migrationBuilder.DropColumn(
                name: "FileTechniqueTaskId",
                table: "FileWorkSteps");

            migrationBuilder.AlterColumn<Guid>(
                name: "TechniqueEntityId",
                table: "FileWorkSteps",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "ProcessesEntityId",
                table: "FileWorkSteps",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "FileProcessesId",
                table: "FileWorkSteps",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier");

            migrationBuilder.AddColumn<Guid>(
                name: "FileWorkStepId1",
                table: "FileTables",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "FileTableRowId",
                table: "FileTableDatas",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Value",
                table: "FileTableDatas",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "FileTableRow",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FileTableId = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileTableRow", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FileTableRow_FileTables_FileTableId",
                        column: x => x.FileTableId,
                        principalTable: "FileTables",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "FileTableStruce",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FieldName = table.Column<string>(nullable: true),
                    DisplayName = table.Column<string>(nullable: true),
                    Enable = table.Column<bool>(nullable: false),
                    Show = table.Column<bool>(nullable: false),
                    Property = table.Column<int>(nullable: false),
                    ColumnType = table.Column<int>(nullable: false),
                    FileTableId = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileTableStruce", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FileTableStruce_FileTables_FileTableId",
                        column: x => x.FileTableId,
                        principalTable: "FileTables",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_FileTables_FileWorkStepId1",
                table: "FileTables",
                column: "FileWorkStepId1");

            migrationBuilder.CreateIndex(
                name: "IX_FileTableDatas_FileTableRowId",
                table: "FileTableDatas",
                column: "FileTableRowId");

            migrationBuilder.CreateIndex(
                name: "IX_FileTableRow_FileTableId",
                table: "FileTableRow",
                column: "FileTableId");

            migrationBuilder.CreateIndex(
                name: "IX_FileTableStruce_FileTableId",
                table: "FileTableStruce",
                column: "FileTableId");

            migrationBuilder.AddForeignKey(
                name: "FK_FileTableDatas_FileTableRow_FileTableRowId",
                table: "FileTableDatas",
                column: "FileTableRowId",
                principalTable: "FileTableRow",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_FileTables_FileWorkSteps_FileWorkStepId1",
                table: "FileTables",
                column: "FileWorkStepId1",
                principalTable: "FileWorkSteps",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_FileWorkSteps_FileProcessess_FileProcessesId",
                table: "FileWorkSteps",
                column: "FileProcessesId",
                principalTable: "FileProcessess",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_FileTableDatas_FileTableRow_FileTableRowId",
                table: "FileTableDatas");

            migrationBuilder.DropForeignKey(
                name: "FK_FileTables_FileWorkSteps_FileWorkStepId1",
                table: "FileTables");

            migrationBuilder.DropForeignKey(
                name: "FK_FileWorkSteps_FileProcessess_FileProcessesId",
                table: "FileWorkSteps");

            migrationBuilder.DropTable(
                name: "FileTableRow");

            migrationBuilder.DropTable(
                name: "FileTableStruce");

            migrationBuilder.DropIndex(
                name: "IX_FileTables_FileWorkStepId1",
                table: "FileTables");

            migrationBuilder.DropIndex(
                name: "IX_FileTableDatas_FileTableRowId",
                table: "FileTableDatas");

            migrationBuilder.DropColumn(
                name: "FileWorkStepId1",
                table: "FileTables");

            migrationBuilder.DropColumn(
                name: "FileTableRowId",
                table: "FileTableDatas");

            migrationBuilder.DropColumn(
                name: "Value",
                table: "FileTableDatas");

            migrationBuilder.AlterColumn<string>(
                name: "TechniqueEntityId",
                table: "FileWorkSteps",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(Guid));

            migrationBuilder.AlterColumn<string>(
                name: "ProcessesEntityId",
                table: "FileWorkSteps",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(Guid));

            migrationBuilder.AlterColumn<Guid>(
                name: "FileProcessesId",
                table: "FileWorkSteps",
                type: "uniqueidentifier",
                nullable: false,
                oldClrType: typeof(Guid),
                oldNullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "FileTechniqueTaskId",
                table: "FileWorkSteps",
                type: "uniqueidentifier",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AddForeignKey(
                name: "FK_FileWorkSteps_FileProcessess_FileProcessesId",
                table: "FileWorkSteps",
                column: "FileProcessesId",
                principalTable: "FileProcessess",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
